// pages/order/carbody/carbody.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgs: [], //上照片路径
    pics: [],//下图片路径
    imagepathurl: 'https://wx.wc5818.com/images/template/tu.png',

  },
  // 添加照片功能
  paizhao: function (e) {
    var that = this;

    wx.chooseImage({
      count: 6,
      sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
      sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
      success(res) {
        var tempFilePaths = res.tempFilePaths; //获取当前图片
        that.setData({
          imgs: that.data.imgs.concat(tempFilePaths)
        })
      }
    })
  },
  // 添加照片功能
  paizhao2: function (e) {
    var that = this;

    wx.chooseImage({
      count: 6,
      sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
      sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
      success(res) {
        var tempFilePaths = res.tempFilePaths; //获取当前图片
        that.setData({
          pics: that.data.pics.concat(tempFilePaths)
        })
      }
    })
  },
  //删除照片功能
  deleteImage: function (e) {
    var that = this;
    var tempFilePaths = that.data.imgs; //获取当前图片
    var index = e.currentTarget.dataset.index; //获取当前长按图片下标
    console.log(tempFilePaths)
    console.log(index)
    wx.showModal({
      title: '提示',
      content: '确定要删除此图片吗？',
      success: function (res) {
        if (res.confirm) {
          console.log('点击确定了');
          // tempFilePaths.splice(index, 1);
          tempFilePaths.splice(index, 1);
        } else if (res.cancel) {
          console.log('点击取消了');
          return false;
        }
        that.setData({
          imgs: tempFilePaths
        });
      }
    })
  },
  //预览照片
  yulan: function (e) {
    var that = this;
    var tempFilePaths = that.data.imgs; //获取当前图片
    var index = e.currentTarget.dataset.index; //获取当前长按图片下标
    wx.previewImage({
      current: tempFilePaths[index],
      urls: tempFilePaths,
    })
  },
  //删除照片功能2
  deleteImage2: function (e) {
    var that = this;
    var tempFilePaths = that.data.pics; //获取当前图片
    var index = e.currentTarget.dataset.index; //获取当前长按图片下标
    console.log(tempFilePaths)
    console.log(index)
    wx.showModal({
      title: '提示',
      content: '确定要删除此图片吗？',
      success: function (res) {
        if (res.confirm) {
          console.log('点击确定了');
          // tempFilePaths.splice(index, 1);
          tempFilePaths.splice(index, 1);
        } else if (res.cancel) {
          console.log('点击取消了');
          return false;
        }
        that.setData({
          pics: tempFilePaths
        });
      }
    })
  },
  //预览照片2
  yulan2: function (e) {
    var that = this;
    var tempFilePaths = that.data.pics; //获取当前图片
    var index = e.currentTarget.dataset.index; //获取当前长按图片下标
    wx.previewImage({
      current: tempFilePaths[index],
      urls: tempFilePaths,
    })
  },
  // 提交事件
  submit:function(){

    wx.navigateTo({
      url: '/pages/order/rizhi2/rizhi2',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})